﻿using BigMonitoringWarningApi.Model.ApiResult;
using GYCTOAManagementSystem.Models.Enum;
using GYCTOAManagementSystemNewApi.Model;
using GYCTOAManagementSystemNewApi.Model.API;
using GYCTOAManagementSystemNewApi.Model.Enum;
using GYCTOAManagementSystemNewApi.Model.Tool;
using GYCTOAManagementSystemNewApi.Public;
using GYCTOAManagementSystemNewApi.Service;
using GYCTOAManagementSystemNewApi.Tool;
using log4net;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.SqlServer.Server;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SharpCompress.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Transactions;

namespace GYCTOAManagementSystemNewApi.Controllers.PublicController
{

    /// <summary>
    /// 存放公共方法
    /// 
    /// 请用#region  分割
    /// 
    /// </summary>
    [ApiExplorerSettings(IgnoreApi = true)]
    [Route("api/[controller]")]
    [ApiController]
    public class PublicMethodApiController : Controller
    {
        DBContext db;
        PublicTool pub;

        #region 数据正式版本
        //public static string FileloadStr = "CompanyFile";
     
        public static string FileloadStr = "CompanyFileHD";
        public static string FileloadMapping = "OAFile";
        public static bool SendAllMesAsyncIsstart = true;
        public static string StaticFilePath = (Path.Combine(Path.GetPathRoot(AppDomain.CurrentDomain.BaseDirectory), PublicMethodApiController.FileloadStr, "1"));

        #endregion

        //#region 数据测试版本
        ////图片文件上传
        //public static string FileloadStr = "CompanyFileTEST";
        ////发送消息通用接口
        //public static bool SendAllMesAsyncIsstart = false;
        //#endregion
        public PublicMethodApiController(DBContext _db)
        {
            db = _db;
            pub = new PublicTool(_db);
        }

        /// <summary> 
        /// 获取所有权限
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetAllRole")]
        public JsonResult GetAllRole()
        {
            //db.Department.Add(new Department() { DepartmentName = "aa", DepartmentNumber = new Guid().ToString() });
            var result = db.Role.Where(x => !x.Delete).ToList();
            return Json(result);
        }

        #region 获取所有信息
        /// <summary>
        /// 获取项目单位属性
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetAllProjectUnitAttribute")]
        public string GetAllProjectUnitAttribute()
        {
            var jsonValue = PublicTool.GetEnumDESVal<ProjectUnitAttributeEnum>();
            return JsonConvert.SerializeObject(jsonValue);
        }
        /// <summary>
        /// 获取所有用户，不排除已离职人员
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetCompanyAllUsers")]
        public JsonResult GetCompanyAllUsers()
        {
            var result = db.Users.Where(x => !x.Delete).OrderBy(x => x.InternshipState).ToList();
            return Json(result);
        }
        /// <summary>
        /// 获取所有项目
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetAllProject")]
        public JsonResult GetAllProject()
        {
            var result = db.Project.Where(x => !x.Delete)/*.OrderByDescending(y => y.CreateDate)*/.ToList();
            return Json(result);
        }

        #region 数据引用实体 
        public class ObjPaylass
        {
            public List<Paylass> children = new List<Paylass>();
            public string label { get; set; }
            public string value { get; set; }
        }

        public class Paylass
        {
            public string value { get; set; }
            public string label { get; set; }
        }
        #endregion

        #endregion

        #region ************************文件上传************************
        private static readonly object formlock = new object();
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="id">上传文件所属数据的id</param>
        /// <param name="FileType">上传文件所属业务类型，例如项目文件、合同文件、规章制度、模板文件</param>
        /// <param name="Type">上传文件具体类型，例如项目任务书或者项目申请书</param>
        /// <param name="Single">添加或者修改文件时是否删除之前的数据</param>
        /// <returns></returns>
        [HttpPost("UploadFile")]
        [AllowAnonymous]
        public JsonResult UploadFile([FromForm] IFormFile file, [FromForm] int FileType, [FromForm] int id, [FromForm] int Type, [FromForm] bool Single)
        {
            bool result = false;
            lock (formlock)
            {
                //ILog log = LogManager.GetLogger(Startup.repository.Name, typeof(CustomerExceptionFilterAttribute));
                //log.Error(FileType.ToString());
                //log.Error(Type.ToString());
                //log.Error(id.ToString());
                //log.Error(Single.ToString());
                //文件类型
                FileType = Convert.ToInt32(Request.Form["FileType"]);   
                //流程Id
                id = Convert.ToInt32(Request.Form["id"]);
                Type = Convert.ToInt32(Request.Form["Type"]);
                //var a = Request.Form["Single"];
                //log.Error(FileType.ToString());
                //log.Error(Type.ToString());
                //log.Error(id.ToString());
                //log.Error(a.ToString());
                Single = Convert.ToBoolean(Request.Form["Single"]);
                try
                {
                    string serverPath = string.Empty;
                    serverPath = GetPaht(FileType, id, Type, Single);
                    List<string> FileNameList = new List<string>();
                    FileNameList.Add(file.FileName);

                    if (FileType.Equals((int)FileTypeEnum.ApkFile))
                    {
                        //ApkFileSettting(serverPath, file, id);
                    }
                    else  if (FileType.Equals((int)FileTypeEnum.UserFile))
                    {
                        //人员备份只保留最新的数据
                        //保存上传的文件
                        if (!Directory.Exists(serverPath))  //判断路径是否存在 不存在创建
                        {
                            DirectoryInfo dirinfo = Directory.CreateDirectory(serverPath);
                            dirinfo.Attributes = FileAttributes.Normal & FileAttributes.Directory;
                        }
                        //Directory.Delete(serverPath,true);
                        PublicTool.SaveFile(serverPath, file, file.FileName); //获取文件名
                    }
                    else 
                    {
                        PublicTool.SaveFile(serverPath, file, file.FileName); //获取文件名
                    }
                    result = true;
                    //if (FileType == 1 && Type == 1)//人员信息的简历和履历
                    //{
                    //    FileNameList.Add(db.Users.Find(id).PersonalResume);
                    //    db.Users.Find(id).PersonalResume = string.Join(",", FileNameList.ToArray());
                    //    db.SaveChanges();
                    //}
                    //else if (FileType == 1 && Type == 2)//人员信息的简历和履历
                    //{
                    //    FileNameList.Add(db.Users.Find(id).SkillsCertificate);
                    //    db.Users.Find(id).SkillsCertificate = string.Join(",", FileNameList.ToArray());
                    //    db.SaveChanges();
                    //}
                }
                catch
                {
                    result = false;
                }
            }
            return Json(result);
        }
        /// <summary>
        /// 根据属性构造路径
        /// </summary>
        /// <param name="FileType"></param>
        /// <param name="id"></param>
        /// <param name="Type"></param>
        /// <param name="Single"></param>
        /// <returns></returns>
        [HttpPost]
        public string GetPaht(int FileType, int id, int Type, bool Single)
        {
            var path = AppDomain.CurrentDomain.BaseDirectory;
            var root = Path.GetPathRoot(path);

            string serverPath = root + FileloadStr + "\\" + "1\\" + FileType;//1代表OA系统
            if (id != 0)
            {
                if (!FileType.Equals((int)FileTypeEnum.ApkFile))
                {
                    serverPath += "\\" + id;
                }
            }
            if (Type != 0)
            {
                serverPath += "\\" + Type;
            }

            if (Single)
            {
                PublicTool.DeleteFile(serverPath, false);
            }
            return serverPath;
        }
        /// <summary>
        /// 检查是否存在文件
        /// </summary>
        /// <param name="id">下载文件所属数据的id</param>
        /// <param name="FileType">下载文件所属业务类型，例如项目文件、合同文件、规章制度、模板文件</param>
        /// <param name="Type">下载文件具体类型，例如项目任务书或者项目申请书</param>
        /// <param name="FileName">待下载文件名</param>
        /// <returns></returns>
        [HttpPost("IsExitFile")]
        public JsonResult IsExitFile([FromBody] dynamic formData)
        {
            JToken j_token = JsonConvert.DeserializeObject<JToken>(formData.ToString());
            int id = Convert.ToInt32(j_token["id"]);
            int FileType = Convert.ToInt32(j_token["FileType"]);
            int Type = Convert.ToInt32(j_token["Type"]);
            string FileName = j_token["FileName"].ToString();

            Message mess = new Message();
            var path = AppDomain.CurrentDomain.BaseDirectory;
            var root = Path.GetPathRoot(path);
            string serverPath = root + FileloadStr + "\\" + "1\\" + FileType;//1代表OA系统
            if (id != 0)
            {
                serverPath += "\\" + id;
            }
            if (Type != 0)
            {
                serverPath += "\\" + Type;
            }
            string filePath = serverPath;
            DirectoryInfo dirinfo = new DirectoryInfo(serverPath);
            if (Directory.Exists(serverPath))
            {
                FileInfo[] files = dirinfo.GetFiles(); // 获取该目录下的所有文件
                if (files.Count() == 0)
                {
                    mess.IsSuccess = false;
                    mess.Msg = "不存在文件";
                }
                else
                {
                    mess.IsSuccess = true;
                }
            }
            return Json(mess);
        }

        /// <summary>
        /// 下载文件
        /// </summary>
        /// <param name="id">下载文件所属数据的id</param>
        /// <param name="FileType">下载文件所属业务类型，例如项目文件、合同文件、规章制度、模板文件</param>
        /// <param name="Type">下载文件具体类型，例如项目任务书或者项目申请书</param>
        /// <param name="FileName">待下载文件名</param>
        /// <returns></returns>
        [HttpGet("DownloadFile")]
        public IActionResult DownloadFile(int id, int FileType, int Type, string FileName)
        {
            FileStreamResult result = null;
            var path = AppDomain.CurrentDomain.BaseDirectory;
            var root = Path.GetPathRoot(path);
            string serverPath = root + FileloadStr + "\\" + "1\\" + FileType;//1代表OA系统
            if (id != 0)
            {
                serverPath += "\\" + id;
            }
            if (Type != 0)
            {
                serverPath += "\\" + Type;
            }
            string filePath = serverPath;
            if (!string.IsNullOrWhiteSpace(FileName))
            {
                filePath = serverPath + "\\" + FileName;
                result = File(new FileStream(filePath, FileMode.Open), "text/plain", Path.GetFileName(filePath));//下载文件
            }
            else
            {
                DirectoryInfo dirinfo = new DirectoryInfo(filePath);
                if (Directory.Exists(filePath))
                {
                    FileInfo[] files = dirinfo.GetFiles(); // 获取该目录下的所有文件
                    if (files.Count() > 1)
                    {
                        filePath = serverPath + ".zip";
                        if (System.IO.File.Exists(filePath))
                        {
                             System.IO.File.Delete(filePath);
                        }
                        ZipHelper.CompressFile(serverPath, filePath);
                    }
                    else if (files.Count() == 1)
                    {
                        filePath = files[0].ToString();
                        //filePath = serverPath + "\\" + files[0];
                    }
                    result = File(new FileStream(filePath, FileMode.Open), "text/plain", Path.GetFileName(filePath));
                }
            }
            return result;
        }


         



        /// <summary>
        /// 下载指定的文件
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        [HttpGet("DownloadFileByName")]

        public ActionResult DownloadFileByName(string filePath )
        {
            var path = AppDomain.CurrentDomain.BaseDirectory;
            var root = Path.GetPathRoot(path);
            // 拼接完整的文件路径
            string serverPath = root + FileloadStr + "\\" + "1\\" + filePath;
      
           var fileName = Path.GetFileName(serverPath); 
           var fileType = Path.GetExtension(serverPath);
            // 验证文件是否存在
            if (!System.IO.File.Exists(serverPath))
            {
                return Content("文件不存在！");
            }

            // 设置响应头，告诉浏览器返回的是指定类型的文件
            HttpContext.Response.ContentType = GetContentType(fileType);
           // HttpContext.Response.AppendHeader("Content-Disposition", $"attachment; filename=\"{fileName}\"");

            // 将文件的内容以流的形式发送给客户端
            return File(serverPath, GetContentType(fileType));
        }

        private string GetContentType(string fileType)
        {
            switch (fileType.ToLower())
            {
                case "pdf":
                    return "application/pdf";
                case "image":
                    return "image/jpeg";
                case "excel":
                    return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                // 添加更多文件类型的处理
                default:
                    return "application/octet-stream";
            }
        }






        /// <summary>
        /// 删除文件
        /// </summary>
        /// <param name="url">待删除文件路径</param>
        /// <returns></returns>
        [HttpGet("DeleteFileByUrl")]
        public JsonResult DeleteFileByUrl(string url)
        {
            bool result = true;
            try
            {
                var path = AppDomain.CurrentDomain.BaseDirectory;
                var root = Path.GetPathRoot(path);
                string newUrl = url.Substring(7, url.Length - 7);
                string serverPath = root + FileloadStr + "\\" + "1" + newUrl;//1代表OA系统
                PublicTool.DeleteFile(serverPath, false);
            }
            catch
            {
                result = false;
            }
            return Json(result);
        }

      


        #endregion

        #region 审批通用泛型方法
        /// <summary>
        /// 判断用户是否有新版审批规则的审批权限
        /// </summary>
        /// <param name="userId">当前登录人id</param>
        /// <param name="ModuleEnum">菜单模块</param>
        /// <param name="money">审批限额</param>
        /// <returns></returns>
        private bool IsNewAuditRight(int userId, string ModuleEnum,int money=0)
        {
            bool isRight = false;
            var auditRight = db.AuditRule.Where(x => !x.Delete && !x.IsRevoke && x.ModuleNumber == ModuleEnum).ToList();
            foreach (var a in auditRight)
            {
                //if ((a.AuditUserId1 == userId && a.AuditUserMoney1 >= money) || (a.AuditUserId2 == userId && a.AuditUserMoney2 >= money) || (a.AuditUserId3 == userId && a.AuditUserMoney3 >= money) || (a.AuditUserId4 == userId && a.AuditUserMoney4 >= money) || (a.AuditUserId5 == userId && a.AuditUserMoney5 >= money) || (a.AuditUserId6 == userId && a.AuditUserMoney6 >= money))
                if (a.AuditUserId1 == userId || a.AuditUserId2 == userId || a.AuditUserId3 == userId || a.AuditUserId4 == userId || a.AuditUserId5 == userId || a.AuditUserId6 == userId)
                {
                    isRight = true;
                    break;
                }
            }
            return isRight;
        }
        #endregion

        #region ************************获取文件下的************************
        [HttpGet("GetUrlDocument")]
        public JsonResult GetUrlDocument(string url)
        {
            PublicTool publicTool = new PublicTool();
            var Liststr = publicTool.GetUrlDocument(url);
            return new JsonResult(new { data = Liststr });
        }
        #endregion


        //#region MyRegion
        ///// <summary>
        ///// 根据用户id和模块编号，查找相应的审批规则
        ///// </summary>
        ///// <param name="ModuleNumber">模块编号</param>
        ///// <param name="SponsorUserid">数据对应用户id</param>
        ///// <returns></returns>
        //public AuditRule GetAuditRule( string ModuleNumber, int SponsorUserid)
        //{
        //    AuditRule auditrule = null;
        //    var user = ALLUserList.Where(x => x.Id == SponsorUserid).FirstOrDefault();
        //    if (user == null) return auditrule;
        //    List<AuditRule> auditRules = ALLAuditRuleList.Where(x => !x.Delete && x.ModuleNumber == ModuleNumber).ToList();
        //    foreach (var a in auditRules)
        //    {
        //        if (a.SponsorUser != null && a.SponsorUser.Split(',').Contains(SponsorUserid.ToString()))
        //        {
        //            auditrule = a;
        //            break;
        //        }
        //    }
        //    if (auditrule == null)
        //    {
        //        foreach (var a in auditRules)
        //        {
        //            if (a.SponsorDepart != null && a.SponsorDepart.Split(',').Contains(user.DepartmentId.ToString()))
        //            {
        //                auditrule = a;
        //                break;
        //            }
        //        }
        //    }
        //    return auditrule;
        //}
        //#endregion

        #region 判断登录人员是否是某部门成员,或者是否是高管部门的成员，从而判断是否有操作权限
        /// <summary>
        /// 判断是否是部门成员,或者是否是高管部门的成员，从而判断是否有操作权限
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="ProjectId"></param>
        /// <returns></returns>
        [HttpPost]
        public bool IsDepartMember(int DepartId, string author, int userId = 0)
        {
            var logid = TokenManage.GetTokenValues(author)[0].Value;
            int userid = Convert.ToInt32(logid);
            bool isMember = false;
            if (userId == 0)
                userId = userid;
            Users user = db.Users.Find(userId);
            //if (user != null && (user.DepartmentId == DepartId || user.DepartmentId == Convert.ToInt32(AuditRightDepartEnum.SeniorManage)))
            //    isMember = true;
            return isMember;
        }
        #endregion


        /// <summary>
        /// 设置最大的采购编号
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public string SetMaxPurchaseNumber(string maxNumber)
        {
            string result = "";
            var date = DateTime.Now.ToString("yyyyMMdd");
            if (maxNumber == null)
            {
                result = date + "001";
            }
            else
            {
                var maxDate = maxNumber.Substring(0, 8);
                var number = maxNumber.Substring(8, 3);
                if (maxDate == date)
                {
                    var newNumber = (Convert.ToInt32(number) + 1).ToString();
                    while (newNumber.Length < 3)
                    {
                        newNumber = "0" + newNumber;
                    }
                    result = date + newNumber;
                }
                else
                {
                    result = date + "001";
                }
            }
            return result;
        }

        #region 审批通用撤销方法
        /// <summary>
        /// 判断当前人员在单据当前的状态下是否有权限
        /// </summary>
        /// <param name="auditRule"></param>
        /// <param name="userid"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        [HttpPost]
        public bool Isjurisdiction(AuditRule auditRule, int userid, int state)
        {
            bool result = false;
            if (state == (int)AuditStateEnum.WaitApprove)
            {
                result = false;
            }
            if (state == (int)AuditStateEnum.One)
            {
                result = auditRule.AuditUserId1.Equals(userid);
            }
            else if (state == (int)AuditStateEnum.Two)
            {
                result = auditRule.AuditUserId2.Equals(userid);
            }
            else if (state == (int)AuditStateEnum.Three)
            {
                result = auditRule.AuditUserId3.Equals(userid);
            }
            else if (state == (int)AuditStateEnum.Four)
            {
                result = auditRule.AuditUserId4.Equals(userid);
            }
            else if (state == (int)AuditStateEnum.Five)
            {
                result = auditRule.AuditUserId5.Equals(userid);
            }
            else if (state == (int)AuditStateEnum.Six)
            {
                result = auditRule.AuditUserId6.Equals(userid);
            }
            return result;
        }

        /// <summary>
        /// 重置 审批状态 + 审批人
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        /// <param name="auditRule"></param>
        /// <param name="state"></param>
        [HttpPost]
        public void RevokeApprovePeople<T>(T t, AuditRule auditRule, int state) where T : PublicAudit
        {
            if (state == (int)AuditStateEnum.One)
            {
                t.AuditComment1 = "";
                t.AuditTime1 = null;
                t.AuditUserId1 = 0;
                t.State = (int)AuditStateEnum.WaitApprove;
            }
            else if (state == (int)AuditStateEnum.Two)
            {
                t.AuditComment2 = "";
                t.AuditTime2 = null;
                t.AuditUserId2 = 0;
                t.State = (int)AuditStateEnum.One;
            }
            else if (state == (int)AuditStateEnum.Three)
            {
                t.AuditComment3 = "";
                t.AuditTime3 = null;
                t.AuditUserId3 = 0;
                t.State = (int)AuditStateEnum.Two;
            }
            else if (state == (int)AuditStateEnum.Four)
            {
                t.AuditComment4 = "";
                t.AuditTime4 = null;
                t.AuditUserId4 = 0;
                t.State = (int)AuditStateEnum.Three;
            }
            else if (state == (int)AuditStateEnum.Five)
            {
                t.AuditComment5 = "";
                t.AuditTime5 = null;
                t.AuditUserId5 = 0;
                t.State = (int)AuditStateEnum.Four;
            }
            else if (state == (int)AuditStateEnum.Six)
            {
                t.AuditComment6 = "";
                t.AuditTime6 = null;
                t.AuditUserId6 = 0;
                t.State = (int)AuditStateEnum.Five;
            }
        }

        /// <summary>
        /// 根据用户id和模块编号，查找相应的审批规则
        /// </summary>
        /// <param name="ModuleNumber">模块编号</param>
        /// <param name="SponsorUserid">数据对应用户id</param>
        /// <returns></returns>
        private AuditRule GetAuditRule(string ModuleNumber, int SponsorUserid)
        {
            AuditRule auditrule = null;
            var user = db.Users.Where(x => x.Id == SponsorUserid).FirstOrDefault();
            if (user == null) return auditrule;
            List<AuditRule> auditRules = db.AuditRule.Where(x => !x.Delete && x.ModuleNumber == ModuleNumber).ToList();
            foreach (var a in auditRules)
            {
                if (a.SponsorUser != null && a.SponsorUser.Split(',').Contains(SponsorUserid.ToString()))
                {
                    auditrule = a;
                    break;
                }
            }
            if (auditrule == null)
            {
                foreach (var a in auditRules)
                {
                    //if (a.SponsorDepart != null && a.SponsorDepart.Split(',').Contains(user.DepartmentId.ToString()))
                    //{
                    //    auditrule = a;
                    //    break;
                    //}
                }
            }
            return auditrule;
        }

        #endregion

        /// 根据枚举值，获取描述
        /// </summary>
        /// <param name="enumValue"></param>
        /// <returns></returns>
        [HttpGet("GetEnumDes")]
        //public static void GetEnumDes(Enum enumValue)
        public JsonResult GetEnumDes()
        {
            List<enumdata> enlis = new List<enumdata>();
            var prpoinfoarray = Enum.GetValues(typeof(ModuleEnum));
            foreach (var prop in prpoinfoarray)
            {
                string desc = string.Empty;
                var attrs = prop.GetType().GetField(prop.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), true);
                if (attrs != null && attrs.Length > 0)
                {
                    DescriptionAttribute descAttr = attrs[0] as DescriptionAttribute;
                    desc = descAttr.Description;
                }
                enlis.Add(new enumdata() { key = prop.ToString(), value = ((int)prop).ToString(), desc = desc });
            }
            return new JsonResult(enlis);
        }



        #region 通用文件查询
        /// <summary>
        /// 通用文件查询 
        /// </summary>
        /// <returns></returns>
        [HttpGet("StaticFileByName")]
        public  ApiResult StaticFileByName([FromBody] string FileName)
        {
            //流程Id
            List<Files> planFiles = PublicTool.GetFileInfo("项目文件内容", "16\\" + 0 + "\\0");
            if (string.IsNullOrEmpty(FileName))
            {
                planFiles = planFiles.Where(x => x.FileName.Contains(FileName)).ToList();
            }
            return ApiResult.True(planFiles);
        }
         
        #endregion

        #region App新增接口

        /// <summary>
        /// 查询返回对应人员,以及拥有权限的模块
        /// </summary>
        /// <param name="formData"></param>
        /// <returns></returns>
        [HttpPost("SelectVagueUserAndMenu")]
        public JsonResult SelectVagueUserAndMenu([FromBody] dynamic formData)
        {
            var author = HttpContext.Request.Headers["Authorization"].ToString().Split(' ')[1];
            var logid = TokenManage.GetTokenValues(author)[0].Value;
            int userId = Convert.ToInt32(logid);
            var right = Convert.ToString(TokenManage.GetTokenValues(author)[2].Value);

            JToken j_token = JsonConvert.DeserializeObject<JToken>(formData.ToString());
            string name = j_token["Name"].ToString();

            var userlis = db.Users.Where(x => x.UserName.Contains(name) && !x.Delete && !x.InternshipState.Equals((int)InternshipStateEnum.Quit)).ToList();

            var rolemenlis = db.rolemenu.Where(x => x.name.Contains(name) && !x.Delete).ToList();
            var allowmenu = new List<rolemenu>();
            foreach (var item in rolemenlis)
            {
                if (right.Contains(item.Roid))
                {
                    allowmenu.Add(item);
                }
            }
            return new JsonResult(new { userlis, allowmenu });
        }

        #endregion

        public ApiResult GetTopPwoerRoleId()
        {

            return ApiResult.True();
        
        }





    }
    public class enumdata
    {
        public string key { get; set; }
        public string value { get; set; }
        public string desc { get; set; }
    }
    public class AuditLis
    {
        public int id { get; set; }
        public int formtype { get; set; }
        public DateTime time { get; set; }
        public decimal money { get; set; }
        public int type { get; set; }
        public int department { get; set; }
        public string remark { get; set; }
        public string address { get; set; }
        public int state { get; set; }
        public bool isRefuse { get; set; }
        public string number { get; set; }
    }
}
